package com.yy.jhl.ui.user.activity;

import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.yy.common.base.BaseActivity;
import com.yy.common.commonutils.LogUtils;
import com.yy.common.commonutils.TimeUtil;
import com.yy.common.commonwidget.OnDoubleClickListener;
import com.yy.common.commonwidget.OnNoDoubleClickListener;
import com.yy.jhl.R;
import com.yy.jhl.ui.manager.activity.NoteActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.yy.jhl.ui.main.activity.TakePhotoUploadActivity.UPLOAD_IMG;

/**
 * Created by libingn on 2017/12/12.
 */

public class ProvisionalCodeSendActivity extends BaseActivity {
    @BindView(R.id.send_type_text)
    TextView sendTypeText;
    @BindView(R.id.history_type_text)
    TextView historyTypeText;
    @BindView(R.id.code_text)
    TextView codeText;
    @BindView(R.id.generate_code_btn)
    Button generateCodeBtn;
    @BindView(R.id.deadline_time_text)
    TextView deadlineTimeText;
    @BindView(R.id.set_dealine_parent)
    LinearLayout setDealineParent;
    @BindView(R.id.receiver_text)
    TextView receiverText;
    @BindView(R.id.add_members_img)
    ImageView addMembersImg;
    @BindView(R.id.receiver_parent)
    LinearLayout receiverParent;
    @BindView(R.id.send_time_text)
    TextView sendTimeText;
    @BindView(R.id.send_time_parent)
    LinearLayout sendTimeParent;
    @BindView(R.id.ensure_btn)
    Button ensureBtn;
    @BindView(R.id.send_parent)
    LinearLayout sendParent;
    @BindView(R.id.history_pull_list_view)
    PullToRefreshListView historyPullListView;
    ListView historyListView;
    @Override
    public int getLayoutId() {
        return R.layout.act_provisional_code_send;
    }

    @Override
    public void initView() {
        showTitle("发送临时账号邀请码", new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
        showRightImageView(R.mipmap.scan_black_icon, new OnDoubleClickListener() {
            @Override
            protected void onDoubleClick(View v) {
                showLongToast("scan");
            }
        });
        sendTimeText.setText(TimeUtil.formatData(TimeUtil.dateFormatYMDHMS,System.currentTimeMillis()));
        showSelectView(true,false);
        sendParent.setVisibility(View.VISIBLE);
        historyPullListView.setVisibility(View.GONE);
        historyListView = historyPullListView.getRefreshableView();
        historyPullListView.setMode(PullToRefreshBase.Mode.DISABLED);
    }
    /**
     * 根据滑动显示不同标题
     */
    private void showSelectView(boolean isSendType,boolean isHistoryType){
        sendTypeText.setTextColor(isSendType ? getResources().getColor(R.color.white) : getResources().getColor(R.color.green_color));
        sendTypeText.setBackgroundResource(isSendType ? R.drawable.green_left_bg : R.drawable.white_left_bg);
        historyTypeText.setTextColor(isHistoryType ? getResources().getColor(R.color.white) : getResources().getColor(R.color.green_color));
        historyTypeText.setBackgroundResource(isHistoryType ? R.drawable.green_right_bg : R.drawable.white_right_bg);
    }
    @OnClick({R.id.send_type_text, R.id.history_type_text, R.id.generate_code_btn, R.id.set_dealine_parent, R.id.receiver_parent, R.id.send_time_parent, R.id.ensure_btn, R.id.send_parent})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.send_type_text:
                showSelectView(true,false);
                sendParent.setVisibility(View.VISIBLE);
                historyPullListView.setVisibility(View.GONE);
                break;
            case R.id.history_type_text:
                showSelectView(false,true);
                sendParent.setVisibility(View.GONE);
                historyPullListView.setVisibility(View.VISIBLE);
                break;
            case R.id.generate_code_btn:
                break;
            case R.id.set_dealine_parent:
                break;
            case R.id.receiver_parent:
                startActivityForResult(ContactListActivity.class,100);
                break;
            case R.id.send_time_parent:
                break;
            case R.id.ensure_btn:
                break;
            case R.id.send_parent:
                break;
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case 100:
                    String result = data.getStringExtra("tel");
                    receiverText.setText(result);
                    break;
            }
        }
    }
}
